package com.example.depcontrol.controller;

import com.example.depcontrol.anno.Log;
import com.example.depcontrol.aop.MyLog;
import com.example.depcontrol.pojo.Dept;
import com.example.depcontrol.pojo.Result;
import com.example.depcontrol.service.DeptService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Slf4j
//@RequestMapping("/depts")
@RestController
public class DeptController {

    @Resource
    private DeptService deptServicelmp;

    @MyLog
    @GetMapping("/depts")
    public Result list() {
        log.info("查询全部部门数据");
        List<Dept> deptList = deptServicelmp.list();
        return Result.success(deptList);
    }

    @Log
    @DeleteMapping("/depts/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除部门:{}", id);//id会替换{}占位符
        deptServicelmp.delete(id);
        return Result.success();
    }

    @Log
    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept){
        log.info("新增部门:{}", dept);
        deptServicelmp.add(dept);
        return Result.success();
    }

    @GetMapping("/depts/{id}")
    public Result checkDep(@PathVariable Integer id){
        log.info("查询部门:{}", id);
        Dept res = deptServicelmp.checkById(id);
        return Result.success(res);
    }

    @PutMapping("/depts")
    public Result alter(@RequestBody Dept dept){
        log.info("修改部门:{}", dept);
        deptServicelmp.alterDep(dept);
        return Result.success();
    }



}
